﻿using Assets.Script.NetSystem.Services.HallService;
using LiteNetLib;
using SimpleTools.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using _2DGame_Preview_Server.Services.RoomAndBattle.RoomHall.Model;
using Newtonsoft.Json;
using Script.NetSystem.Services.RoomAndBattle.RoomService;
using Script.UiSystem;
using Script.UiSystem.Hall;
using Script.UiSystem.Room;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Assets.Script.NetSystem.Services.RoomAndBattle.HallService.Handler
{
    public class JoinRoom : IHallHandler
    {
        private RoomClient roomClient;

        public void Handler(HallClient hallClient, JsonData jsonData)
        {
            try
            {
                RoomInfo roomInfo = JsonConvert.DeserializeObject<RoomInfo>(jsonData.GetStr("roomInfo"));
                hallClient.CloseConnect();

                new RoomController(roomInfo.port);
                
                
                SceneManager.LoadScene("RoomTemp");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }

    }
}
